package cn.wjc.demo.partone.service.impl;

import cn.wjc.demo.common.entity.Teacher;
import cn.wjc.demo.partone.mapper.ITeacherMapper;
import cn.wjc.demo.partone.service.ITeacherService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TeacherServiceImpl implements ITeacherService {

    private final ITeacherMapper teacherMapper;

    @Override
    public void addTeacher(Teacher teacher) {
        log.info("正在执行【新增教师】的业务...");
        teacherMapper.insert(teacher);
    }

    @Override
    public List<Teacher> queryListTeacher(Teacher teacher) {
        LambdaQueryWrapper<Teacher> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(teacher.getTId()), Teacher::getTId, teacher.getTId())
                .like(StringUtils.hasText(teacher.getTName()), Teacher::getTName, teacher.getTName());
        queryWrapper.orderByAsc(Teacher::getTId);

        return teacherMapper.selectList(queryWrapper);
    }
}
